package sword_offer;

import common.TreeNode;

/**
 * @ClassName _27MirrorTree
 * @Description: 二叉树的镜像
 * @Author: yongliang.ma
 * @Create_time:2022/10/9 13:44
 */
public class _27MirrorTree {

    // 获取二叉树的镜像
    public TreeNode mirrorTree(TreeNode treeNode){
        swap(treeNode);
        return treeNode;
    }

    public void swap(TreeNode treeNode){
        if (treeNode == null)
            return;
        TreeNode temp = treeNode.left;
        treeNode.left = treeNode.right;
        treeNode.right = temp;
        swap(treeNode.left);
        swap(treeNode.right);
    }
}
